package com.aaa.custom.controller.cartController;

import com.aaa.custom.service.cart.CartService;
import com.aaa.entity.cart_order.kwc.Cart;
import com.aaa.entity.cart_order.kwc.CartList;
import com.aaa.util.CalculatePrice;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * fileName:CartController
 * description:
 * author:xxx
 * createTime:2020/2/14 13:50
 * version:1.0.0
 */
@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    private CartService cartService;
    CalculatePrice calculatePrice = new CalculatePrice();

    /**
     * 根据用户id及店铺id查询购物车列表，并返回购物车总价
     * @param member_id
     * @param shop_id
     * @return
     */
    @RequestMapping("list")
    public Object getCartList(long member_id,long shop_id){


        return calculatePrice.calculateCart(cartService.getCartById(member_id,shop_id));
    }

    /**
     *  根据用户id及店铺id清空购物车
     * @param member_id
     * @param shop_id
     * @return
     */
    @RequestMapping("deleteAll")
    public Object deleteAll(long member_id,long shop_id){

        cartService.deleteAll( member_id,shop_id);
        return cartService.getCartById(member_id,shop_id);
    }


    /**
     * 添加购物车
     * @param
     * @return
     */
    @RequestMapping("addCart")
    public Object addCart(@RequestBody CartList cart){
//        System.out.println(cart);
        return cartService.addCart(cart);
    }

    /**
     * 购物车数量减一
     * @param cart
     * @return
     */
    @RequestMapping("subtractCart")
    public Object subtractCart(@RequestBody CartList cart){

        return cartService.subtractCart(cart);

    }

}
